<?php
if (isset($_POST['function']))
{
    $function = $_POST['function'];
    unset($_POST['function']);
    call_user_func_array($function, $_POST);
}
function getMetascore($title)
{
    $title = str_replace(' ', '-', $title);
    $title = strtolower($title);
    $url = "www.metacritic.com/game/pc/%s";
    $url = sprintf($url, $title);
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($curl);
    $result = array();
    $regex = '/<span class="score_value" property="v:average">(.*?)<\/span>/';
    if (preg_match($regex, $data, $result))
    {
        $metascore = substr($result[0], strpos($result[0], '>') + 1);
        $metascore = substr($metascore, 0, strpos($metascore, '<'));
        echo $metascore;
    }
    else
        echo 0;
}
?>
